28
Easy2Siksha
Repeat this process until every group has only one item.
4. Combine the Groups
Once all the groups have only one item, combine them back together in order. For our
example:
1. [1] + [2] + [3] becomes [1, 2, 3]
2. [6] + [7] + [8] + [9] becomes [6, 7, 8, 9]
Finally, combine everything:
[1, 2, 3] + [5] + [6, 7, 8, 9] = [1, 2, 3, 5, 6, 7, 8, 9]
Analogy
Imagine you are arranging books by height. You pick one book (the pivot) and place shorter
books on the left and taller books on the right. Then, you repeat the process for each
smaller pile until every pile has just one book. Finally, stack the books together, and they’re
in order!
(b) Merge Sort
Merge Sort is like solving the problem of sorting by “divide and conquer.” Instead of
organizing everything at once, you repeatedly split the messy pile into smaller, manageable
parts, sort those parts, and then merge them back together into one neat pile.
1. Divide the List into Halves
Imagine you’re trying to organize a messy pile of cards. Instead of sorting the entire pile at
once, you split it into two smaller piles.
Take this list:
[8, 3, 5, 1, 9, 6, 2, 7]
Split it into two halves:
• Left half: [8, 3, 5, 1]
• Right half: [9, 6, 2, 7]
2. Keep Splitting Until Each Pile Has One Item
Now, split each of these halves again, and keep splitting until each pile has just one number:
• [8, 3, 5, 1] → [8, 3] and [5, 1] → [8], [3], [5], [1]
• [9, 6, 2, 7] → [9, 6] and [2, 7] → [9], [6], [2], [7]
At this stage, you have a bunch of tiny piles, each with only one number.